package com.lekang.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lekang.common.annotation.Log;
import com.lekang.common.core.controller.BaseController;
import com.lekang.common.core.domain.AjaxResult;
import com.lekang.common.enums.BusinessType;
import com.lekang.system.domain.VisitorRegistration;
import com.lekang.system.service.IVisitorRegistrationService;
import com.lekang.common.utils.poi.ExcelUtil;
import com.lekang.common.core.page.TableDataInfo;

/**
 * 来访登记Controller
 * 
 * @author ruoyi
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/system/visitor_registration")
public class VisitorRegistrationController extends BaseController
{
    @Autowired
    private IVisitorRegistrationService visitorRegistrationService;

    /**
     * 查询来访登记列表
     */
//    @PreAuthorize("@ss.hasPermi('system:visitor_registration:list')")
    @GetMapping("/list")
    public TableDataInfo list(VisitorRegistration visitorRegistration)
    {
        startPage();
        List<VisitorRegistration> list = visitorRegistrationService.selectVisitorRegistrationList(visitorRegistration);
        return getDataTable(list);
    }

    /**
     * 导出来访登记列表
     */
//    @PreAuthorize("@ss.hasPermi('system:visitor_registration:export')")
//    @Log(title = "来访登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VisitorRegistration visitorRegistration)
    {
        List<VisitorRegistration> list = visitorRegistrationService.selectVisitorRegistrationList(visitorRegistration);
        ExcelUtil<VisitorRegistration> util = new ExcelUtil<VisitorRegistration>(VisitorRegistration.class);
        util.exportExcel(response, list, "来访登记数据");
    }

    /**
     * 获取来访登记详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:visitor_registration:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(visitorRegistrationService.selectVisitorRegistrationById(id));
    }

    /**
     * 新增来访登记
     */
//    @PreAuthorize("@ss.hasPermi('system:visitor_registration:add')")
//    @Log(title = "来访登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VisitorRegistration visitorRegistration)
    {
        return toAjax(visitorRegistrationService.insertVisitorRegistration(visitorRegistration));
    }

    /**
     * 修改来访登记
     */
//    @PreAuthorize("@ss.hasPermi('system:visitor_registration:edit')")
//    @Log(title = "来访登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VisitorRegistration visitorRegistration)
    {
        return toAjax(visitorRegistrationService.updateVisitorRegistration(visitorRegistration));
    }

    /**
     * 删除来访登记
     */
//    @PreAuthorize("@ss.hasPermi('system:visitor_registration:remove')")
//    @Log(title = "来访登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(visitorRegistrationService.deleteVisitorRegistrationByIds(ids));
    }

//    @PreAuthorize("@ss.hasPermi('system:visitor_registration:byVisitorType')")
    @GetMapping("/byVisitorType")
    public AjaxResult selectByVisitorType( VisitorRegistration visitorRegistration){
        List<VisitorRegistration> list = visitorRegistrationService.selectVisitorRegistrationList(visitorRegistration);
        return AjaxResult.success(list);
    }
}
